﻿// Page1.cpp : 实现文件
//

#include "stdafx.h"
#include "MobileGame.h"
#include "MobileGameDlg.h"
#include "Page1.h"
#include "afxdialogex.h"
#include "tlhelp32.h"

// CPage1 对话框
CPage1 * g_pPage1 = NULL;

IMPLEMENT_DYNAMIC(CPage1, CDialogEx)

CPage1::CPage1(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_PAGE1, pParent)
{

}

CPage1::~CPage1()
{
}

void CPage1::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_Simulator_Path, m_edit_simulator_path);
	DDX_Control(pDX, IDC_COMBO_MoreOpen_Set, m_combo_moreopen_set);
	DDX_Control(pDX, IDC_COMBO_Opt_Cpu_Set, m_combo_opt_cpu_set);
	DDX_Control(pDX, IDC_LIST_OriginalTask_Info, m_list_oritask_info);
	DDX_Control(pDX, IDC_LIST_NeedDealTask_Info, m_list_needdealtask_info);
}


BEGIN_MESSAGE_MAP(CPage1, CDialogEx)
	ON_BN_CLICKED(IDC_BTN_HengXiang, &CPage1::OnBnClickedBtnHengxiang)
	ON_BN_CLICKED(IDC_BTN_HANDLE_BIND, &CPage1::OnBnClickedBtnHandleBind)
	ON_BN_CLICKED(IDC_BTN_SUSPEND, &CPage1::OnBnClickedBtnSuspend)
	ON_BN_CLICKED(IDC_BTN_SAVE, &CPage1::OnBnClickedBtnSave)
	ON_BN_CLICKED(IDC_BTN_AddToNeedDeal, &CPage1::OnBnClickedBtnAddtoneeddeal)
	ON_BN_CLICKED(IDC_BTN_DelFromNeedDeal, &CPage1::OnBnClickedBtnDelfromneeddeal)
	ON_BN_CLICKED(IDC_BTN_InsertNeedDeal, &CPage1::OnBnClickedBtnInsertneeddeal)
	ON_BN_CLICKED(IDC_BTN_Insert_NeedDeal_Down, &CPage1::OnBnClickedBtnInsertNeeddealDown)
	ON_BN_CLICKED(IDC_BTN_Move_Up, &CPage1::OnBnClickedBtnMoveUp)
	ON_BN_CLICKED(IDC_BTN_Move_Down, &CPage1::OnBnClickedBtnMoveDown)
	ON_BN_CLICKED(IDC_BTN_ClearNeedDeal, &CPage1::OnBnClickedBtnClearneeddeal)
	ON_BN_CLICKED(IDC_BTN_OneKeyToNeedDeal_OfMainTask, &CPage1::OnBnClickedBtnOnekeytoneeddealOfmaintask)
	ON_BN_CLICKED(IDC_Btn_OneKeyToFB, &CPage1::OnBnClickedBtnOnekeytofb)
	ON_BN_CLICKED(IDC_BTN_ADD_FRIEND, &CPage1::OnBnClickedBtnAddFriend)
	ON_NOTIFY(NM_CLICK, IDC_LIST_OriginalTask_Info, &CPage1::OnNMClickListOriginaltaskInfo)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_OriginalTask_Info, &CPage1::OnNMDblclkListOriginaltaskInfo)
	ON_NOTIFY(NM_CLICK, IDC_LIST_NeedDealTask_Info, &CPage1::OnNMClickListNeeddealtaskInfo)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_NeedDealTask_Info, &CPage1::OnNMDblclkListNeeddealtaskInfo)
	ON_COMMAND(ID_Memu_ImportAccount, &CPage1::OnMemuImportaccount)
	ON_BN_CLICKED(IDC_BROWSER, &CPage1::OnBnClickedBrowser)
	ON_BN_CLICKED(IDC_BTN_CLOSE_ALL, &CPage1::OnBnClickedBtnCloseAll)
END_MESSAGE_MAP()


// CPage1 消息处理程序

DWORD WINAPI StartAdsl(LPVOID lParam)
{
	//第一次拨号
	while (true) {
		g_pPage1->SetDlgItemTextW(IDC_STATIC_PAGE1_ADSLNUM, NumberToString(g_IniFile.GetInt(L"Set", L"AdslNum")));

		if (g_IniFile.GetInt(L"Set", L"StartAdsl") == 0) {
			g_pPage1->SetDlgItemTextW(IDC_STATIC_PAGE1_CODE, L"当前vpn账号:");
			sendAdsl();
			//判断连接是否成功成功
			adsl.GetAdslStyle();
			CString sIP = adsl.GetAdslIp();
			if (sIP != L"") {
				g_IniFile.SetInt(L"Set", L"StartAdsl", 1);
			}
			
		}
		//else {
		//	//检测拨号是否断线 断线重拨
		//	if (GetNetIp() != g_IniFile.GetString(L"Set", L"IP")) {
		//		sendAdsl();
		//	}
		//	//if (g_IniFile.GetInt(L"Set", L"AdslNum") == 0) {
		//	//	sendAdsl();
		//	//}
		//}
		
		adsl.GetAdslStyle();
		TRACE("\n net:%d",adsl.GetConnectState());
		CString sIP = adsl.GetAdslIp();
		TRACE("currentIP:%s\n", sIP);

		if (sIP == L"") {
			g_IniFile.SetInt(L"Set", L"StartAdsl", 0);
		}
		TRACE("检测状态:%s\n", sIP);

		if (m_CheckState) {
			long nMapHwnd = (long)m_GlobalDM->FindWindow(L"", L"MapleStory");
			//掉线处理
			long lWidth = m_GlobalDM->GetScreenWidth();
			if (nMapHwnd > 0 && m_GlobalDM->GetScreenWidth()<1000) {

				KillProcess(L"MapleStory.exe");
				KillProcess(L"GameLauncher.exe");
				
				sendAdsl();
				m_CheckState = false;
			}
			nMapHwnd = (long)m_GlobalDM->FindWindow(L"MapleStoryClass", L"MapleStory");
			if (nMapHwnd <= 0) {
				m_GState = false;
				m_CheckState = false;
				
			}
		}
		Sleep(5000);
		DbgOut("checkAdsl");
	}

	////取配置文件
	//if (g_IniFile.GetString(L"Set", L"IP") == "" && g_IniFile.GetInt(L"Set", L"AdslNum") == 0) {
	//	//开始拨号

	//}
	return 0;
}


DWORD WINAPI StartThread(LPVOID lParam)
{
	CString str;
	while (true)//检测是否已经连接
	{
		g_pPage1->SetDlgItemTextW(IDC_STATIC_PAGE1_STATE, L"");
		if (g_IniFile.GetString(L"Set", L"IP") != "" ) {
			break;
		}
		for (size_t i = 0; i < 5; i++)
		{
			str += L".";
				g_pPage1->SetDlgItemTextW(IDC_STATIC_PAGE1_STATE, L"等待连接" + str);
		}
		str = L"";
		DbgOut("等待连接");
		Sleep(3000);
	}
	if (g_IniFile.GetString(L"Set", L"IP") != "") {
		g_pPage1->SetDlgItemTextW(IDC_STATIC_PAGE1_STATE, L"连接成功");
	}

	int iCount = g_MobileGameDlg->m_list_info.GetItemCount();

	m_GNum = 0;//全局
	


	for (int i = 0; i < iCount; i++)
	{
		i = g_IniFile.GetInt(L"Set", L"Num");
		//TODO:vpn处理
		CString strSet;
		strSet.Format(L"%d", i + 1);
		//int iFinishState = g_AccountFile.GetInt(strSet, L"完成");
		//if (iFinishState == 1 || iFinishState == 2 || iFinishState == 3)
		//{
		//	DbgOut(L"[sdn] 再次来循环");
		//	continue;
		//}
		CString strState = g_MobileGameDlg->m_list_info.GetItemText(i, 6);
		if (strState != L"账号错误" &&
			strState != L"二密错误" &&
			strState != L"运行中" &&
			strState != L"完成" &&
			strState != L"封号")
		{
			//开始执行游戏
			m_GState = true; //全局运行状态
			DealCurTaskProcess(i);
			
		}
		if (strState == L"完成" || strState == L"二密错误" || strState == L"账号错误") {
			g_IniFile.SetInt(L"Set", L"Num", ++i);
		}
		
	}
	//g_pPage1->GetDlgItem(IDC_BTN_HANDLE_BIND)->EnableWindow(TRUE);
	return 0;
}


void CPage1::OnBnClickedBtnHengxiang()
{
	// TODO: 在此添加控件通知处理程序代码
	int nWidth = 0, nHeight = 0;

	nWidth = 150 + 100;
	nHeight = 200;

	HWND hHandle = NULL;
	CString strTitle;
	int x, y;
	int j = 0;
	int k = 0;
	int m = 0;
	for (int i = 0; i < 15; i++)
	{
		if (i <= 4)
		{
			if (i == 0)
			{
				strTitle = L"雷电模拟器";
			}
			else
			{
				strTitle.Format(L"雷电模拟器-%d", i);
			}

			hHandle = ::FindWindow(L"LDPlayerMainFrame", strTitle);
			if (hHandle != NULL)
			{
				x = 5 + nWidth*j;
				y = 5;
				j++;
				::SetWindowPos(hHandle, HWND_BOTTOM, x, y, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
				::SetForegroundWindow(hHandle);
				Sleep(20);
			}
		}
		else if (i <= 9 && i > 4)
		{
			strTitle.Format(L"雷电模拟器-%d", i);
			hHandle = ::FindWindow(L"LDPlayerMainFrame", strTitle);
			if (hHandle != NULL)
			{
				x = 5 + nWidth*k;
				y = 5 + 400;
				k++;
				::SetWindowPos(hHandle, HWND_BOTTOM, x, y, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
				::SetForegroundWindow(hHandle);
				Sleep(20);
			}
		}
		else if (i > 9)
		{
			strTitle.Format(L"雷电模拟器-%d", i);
			hHandle = ::FindWindow(L"LDPlayerMainFrame", strTitle);
			if (hHandle != NULL)
			{
				x = 5 + nWidth*m;
				y = 5 + 400 * 2;
				m++;
				::SetWindowPos(hHandle, HWND_BOTTOM, x, y, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
				::SetForegroundWindow(hHandle);
				Sleep(20);
			}
		}

	}
}


void CPage1::OnBnClickedBtnHandleBind()
{
	// TODO: 在此添加控件通知处理程序代码
	//m_GGameHwnd = (long)m_GlobalDM->FindWindow(L"MapleStoryClass", L"MapleStory");
	//long xx = m_GlobalDM->IsBind(m_GGameHwnd);
	//if (!xx) {
	//	int ret = m_GlobalDM->BindWindowEx(m_GGameHwnd, L"gdi", L"normal", L"normal", L"", 0);
	//}

	////m_GlobalDM->SetWindowState(m_GGameHwnd, 12);
	////m_GlobalDM->delay(2000);
	////if (runScript(L"taskBossOut")) {
	////	//if (intX.lVal > 0) {
	////	//	m_GlobalDM->KeyDown(39);
	////	//	if (intX.lVal - 512<120) {
	////	//		m_GlobalDM->delay(100);
	////	//	}
	////	//	else {
	////	//		m_GlobalDM->delay((intX.lVal - 512)*0.66 * 10 + 100);
	////	//	}
	////	//	
	////	//	m_GlobalDM->KeyUp(39);

	////	//}
	////}
	////CString str;
	////long xxxx = (intX.lVal - 512)*0.66*10;
	////
	////str.Format(L"%d-%d", intX.lVal, xxxx);
	////AfxMessageBox(str);
	//CString strSimulatorPath;
	//m_edit_simulator_path.GetWindowTextW(strSimulatorPath);
	////if (strSimulatorPath.IsEmpty())
	////{
	////	AfxMessageBox(L"模拟器路径出错,是否没安装?");
	////	return;
	////}
	GetDlgItem(IDC_BTN_HANDLE_BIND)->EnableWindow(FALSE);
	//开启拨号线程
	CloseHandle(::CreateThread(NULL, 0, StartAdsl, NULL, 0, NULL));
	Sleep(2000);
	//MainTask(2);
	CloseHandle(::CreateThread(NULL, 0, StartThread, NULL, 0, NULL));
}


BOOL CPage1::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	g_pPage1 = this;

	ListView_SetExtendedListViewStyle(m_list_oritask_info.GetSafeHwnd(),
		LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_GRIDLINES);    //网格线 //LVS_EX_CHECKBOXES
	m_list_oritask_info.InsertColumn(0, L"任务种类-双击添加", LVCFMT_CENTER, 120);

	ListView_SetExtendedListViewStyle(m_list_needdealtask_info.GetSafeHwnd(),
		LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_GRIDLINES);    //网格线 //LVS_EX_CHECKBOXES
	m_list_needdealtask_info.InsertColumn(0, L"等待运行-双击删除", LVCFMT_CENTER, 120);

	int iIndex = 0;
	m_combo_moreopen_set.InsertString(iIndex++, L"1");
	m_combo_moreopen_set.InsertString(iIndex++, L"2");
	m_combo_moreopen_set.InsertString(iIndex++, L"3");
	m_combo_moreopen_set.InsertString(iIndex++, L"4");
	m_combo_moreopen_set.InsertString(iIndex++, L"5");
	m_combo_moreopen_set.InsertString(iIndex++, L"6");
	m_combo_moreopen_set.InsertString(iIndex++, L"8");
	m_combo_moreopen_set.InsertString(iIndex++, L"10");
	m_combo_moreopen_set.SetCurSel(0);

	m_combo_opt_cpu_set.AddString(_T("20"));
	m_combo_opt_cpu_set.AddString(_T("30"));
	m_combo_opt_cpu_set.AddString(_T("40"));
	m_combo_opt_cpu_set.AddString(_T("50"));
	m_combo_opt_cpu_set.SetCurSel(0);

	InitOriTaskListInfo();

	IniToPage();

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}

void CPage1::InitOriTaskListInfo()
{
	int iTaskNumber = m_GameTask_Page1.m_OriTaskArray.GetSize();
	for (int i = 0; i < iTaskNumber; i++)
	{
		m_list_oritask_info.InsertItem(i, m_GameTask_Page1.m_OriTaskArray.GetAt(i));
	}
}

void CPage1::PageToIni()
{
	CString strSimulatorPath, strMoreOpen, strOptCpu;
	m_edit_simulator_path.GetWindowText(strSimulatorPath);
	if (!strSimulatorPath.IsEmpty())
	{
		g_IniFile.SetString(_T("Set"), _T("模拟器路径"), strSimulatorPath);
	}
	m_combo_moreopen_set.GetWindowText(strMoreOpen);
	if (!strMoreOpen.IsEmpty())
	{
		g_IniFile.SetInt(_T("Set"), _T("多开数量"), _ttoi(strMoreOpen));
	}
	m_combo_opt_cpu_set.GetWindowText(strOptCpu);
	if (!strOptCpu.IsEmpty())
	{
		g_IniFile.SetInt(_T("Set"), _T("优化CPU"), _ttoi(strOptCpu));
	}

	//获取日期数据 如果为空 不为空或不等于当前日期 则设置账号数据的状态
	//当前日期为空 则记录的vpn为空 当前日期不等于配置日期 则vpn名称为空


	CStringArray strCurTaskArray;
	g_IniFile.GetSectionKeys(L"CurTask", strCurTaskArray);
	for (int i = 0; i < strCurTaskArray.GetSize(); i++)
	{
		g_IniFile.Delete(L"CurTask", NumberToString(i));
	}

	int iCurTaskNumber = m_list_needdealtask_info.GetItemCount();
	for (int i = 0; i < iCurTaskNumber; i++)
	{
		CString strTaskName = m_list_needdealtask_info.GetItemText(i, 0);
		g_IniFile.SetString(L"CurTask", NumberToString(i), strTaskName);
	}
}


void CPage1::IniToPage()
{
	//模拟器路径|多开设置|优化CPU|窗口分布|要做的任务列表
	CString strSimulatorPath = g_IniFile.GetString(_T("Set"), _T("模拟器路径"));
	if (!strSimulatorPath.IsEmpty())
	{
		m_edit_simulator_path.SetWindowText(strSimulatorPath);
	}
	else
	{
		CString strLeiDianPath = L"";// GetSimulatorPath();
		if (!strLeiDianPath.IsEmpty())
		{
			m_edit_simulator_path.SetWindowText(strLeiDianPath);
		}
	}
	int iMoreOpen = g_IniFile.GetInt(_T("Set"), _T("多开数量"));
	if (iMoreOpen != 0)
	{
		m_combo_moreopen_set.SetWindowText(NumberToString(iMoreOpen));
	}
	int iOptCpu = g_IniFile.GetInt(_T("Set"), _T("优化CPU"));
	if (iOptCpu != 0)
	{
		m_combo_opt_cpu_set.SetWindowText(NumberToString(iOptCpu));
	}

	if (g_IniFile.GetInt(_T("Set"), _T("工作模式")) == 1)
	{
		((CButton*)GetDlgItem(IDC_CHECK_Task))->SetCheck(1);
		((CButton*)GetDlgItem(IDC_CHECK_Debug))->SetCheck(0);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_CHECK_Task))->SetCheck(0);
		((CButton*)GetDlgItem(IDC_CHECK_Debug))->SetCheck(1);
	}

	int iRet = g_IniFile.GetInt(_T("Set"), _T("执行"));
	if (iRet == 1)
	{
		((CButton*)GetDlgItem(IDC_CHECK_QiHao))->SetCheck(1);
	}
	else if (iRet == 2)
	{
		((CButton*)GetDlgItem(IDC_CHECK_RiChang))->SetCheck(1);
	}
	else if (iRet == 3)
	{
		((CButton*)GetDlgItem(IDC_CHECK_Add_Friend))->SetCheck(1);
	}

	if (g_IniFile.GetInt(L"Set", L"日常任务") == 0)
	{
		((CButton*)GetDlgItem(IDC_CHECK_RiChang_DanRen))->SetCheck(1);
		((CButton*)GetDlgItem(IDC_CHECK_RiChang_ZuDui))->SetCheck(0);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_CHECK_RiChang_DanRen))->SetCheck(0);
		((CButton*)GetDlgItem(IDC_CHECK_RiChang_ZuDui))->SetCheck(1);
	}


	CStringArray strCurTaskArray;
	g_IniFile.GetSectionKeys(_T("CurTask"), strCurTaskArray);

	for (int i = 0; i < strCurTaskArray.GetSize(); i++)
	{
		CString strTaskName = g_IniFile.GetString(_T("CurTask"), NumberToString(i));
		//CString strTaskName = strCurTaskArray.GetAt(i);
		m_list_needdealtask_info.InsertItem(i, strTaskName);
	}
}



void CPage1::OnBnClickedBtnSuspend()
{
	// TODO: 在此添加控件通知处理程序代码
	m_GlobalDM->UnBindWindow();
	m_GGameHwnd = (long)m_GlobalDM->FindWindow(L"MapleStoryClass", L"MapleStory");
	int ret = m_GlobalDM->BindWindowEx(m_GGameHwnd, L"gdi", L"normal", L"normal", L"", 0);
	m_GlobalDM->delay(2000);
	for (size_t i = 0; i < 10; i++)
	{
		m_GlobalDM->KeyDown(39);
		m_GlobalDM->delay(200);
		m_GlobalDM->KeyPress(18);
		m_GlobalDM->KeyUp(39);
		m_GlobalDM->KeyDown(39);
		m_GlobalDM->delay(200);
		m_GlobalDM->KeyPress(18);
		m_GlobalDM->KeyUp(39);

		m_GlobalDM->delay(500);
		
	}
	for (size_t i = 0; i < 10; i++)
	{
		m_GlobalDM->KeyDown(37);
		m_GlobalDM->delay(200);
		m_GlobalDM->KeyPress(18);
		m_GlobalDM->KeyUp(37);
		m_GlobalDM->KeyDown(37);
		m_GlobalDM->delay(200);
		m_GlobalDM->KeyPress(18);
		m_GlobalDM->KeyUp(37);

		m_GlobalDM->delay(500);

	}
	//CloseHandle(::CreateThread(NULL, 0, StartThread, NULL, 0, NULL));
}


void CPage1::OnBnClickedBtnSave()
{
	// TODO: 在此添加控件通知处理程序代码

	PageToIni();

	//先清空配置文件
	CStringArray strCurTaskArray;
	g_IniFile.GetSectionKeys(_T("CurTask"), strCurTaskArray);

	for (int i = 0; i < strCurTaskArray.GetSize(); i++)
	{
		g_IniFile.Delete(_T("CurTask"), NumberToString(i));
	}
	int iTaskNumber = m_list_needdealtask_info.GetItemCount();
	for (int i = 0; i < iTaskNumber; i++)
	{
		CString strTaskName = m_list_needdealtask_info.GetItemText(i, 0);
		g_IniFile.SetString(_T("CurTask"), NumberToString(i), strTaskName);
	}
}


void CPage1::OnBnClickedBtnAddtoneeddeal()
{
	// TODO: 在此添加控件通知处理程序代码

	POSITION pos = m_list_oritask_info.GetFirstSelectedItemPosition();
	if (pos == NULL)
	{
		AfxMessageBox(_T("请选中一行或多行进行添加."));
	}
	else
	{
		while (pos)
		{
			int nItem = m_list_oritask_info.GetNextSelectedItem(pos);
			CString strTaskName = m_list_oritask_info.GetItemText(nItem, 0);

			int nIndex = m_list_needdealtask_info.GetItemCount();
			m_list_needdealtask_info.InsertItem(nIndex, strTaskName);

		}
	}
}


void CPage1::OnBnClickedBtnDelfromneeddeal()
{
	// TODO: 在此添加控件通知处理程序代码
	POSITION pos = m_list_needdealtask_info.GetFirstSelectedItemPosition();
	if (pos == NULL)
	{
		AfxMessageBox(_T("请选中一行或多行进行删除."));
	}
	else
	{
		while (pos)
		{
			int nItem = m_list_needdealtask_info.GetNextSelectedItem(pos);
			m_list_needdealtask_info.DeleteItem(nItem);

		}
	}
}


void CPage1::OnBnClickedBtnInsertneeddeal()
{
	// TODO: 在此添加控件通知处理程序代码
	int iChooseItem = m_list_needdealtask_info.GetSelectionMark();
	if (iChooseItem == -1)
	{
		AfxMessageBox(L"请选中");
		return;
	}

	if (iChooseItem != -1)
	{
		int iPos = m_list_oritask_info.GetSelectionMark();
		if (iPos != -1)
		{
			CString strTaskName = m_list_oritask_info.GetItemText(iPos, 0);
			m_list_needdealtask_info.InsertItem(iChooseItem, strTaskName);
		}
	}
	else
	{
		AfxMessageBox(_T("插入的步骤:选中[要做任务列表]某行A,再选中[初始任务列表]某行B,点击插入,即将B插入A之后."));
	}
}


void CPage1::OnBnClickedBtnInsertNeeddealDown()
{

	int iChooseItem = m_list_needdealtask_info.GetSelectionMark();
	if (iChooseItem == -1)
	{
		AfxMessageBox(L"请选中");
		return;
	}

	if (iChooseItem != -1)
	{
		int iPos = m_list_oritask_info.GetSelectionMark();
		if (iPos != -1)
		{
			CString strTaskName = m_list_oritask_info.GetItemText(iPos, 0);

			m_list_needdealtask_info.InsertItem(iChooseItem + 1, strTaskName);
		}
	}
	else
	{
		AfxMessageBox(_T("插入的步骤:选中[要做任务列表]某行A,再选中[初始任务列表]某行B,点击插入,即将B插入A之后."));
	}
}


void CPage1::OnBnClickedBtnMoveUp()
{
	// TODO: 在此添加控件通知处理程序代码
	m_list_needdealtask_info.SetFocus();
	if (m_iSelect_NeedListCtrl_Index == -1)
	{
		AfxMessageBox(L"请先选中");
		return;
	}

	// 判断所选项是否位于行首
	if (m_iSelect_NeedListCtrl_Index == 0)
	{
		AfxMessageBox(L"已经位于第一行!");
		return;
	}
	// 提取所选列表项各列类容
	CString tempField1;
	tempField1 = m_list_needdealtask_info.GetItemText(m_iSelect_NeedListCtrl_Index, 0);

	// 删除所选列表项
	m_list_needdealtask_info.DeleteItem(m_iSelect_NeedListCtrl_Index);
	// 在IndexInFieldList-1位置处插入上面所删列表项的各列类容
	int tempItem;
	tempItem = m_list_needdealtask_info.InsertItem(m_iSelect_NeedListCtrl_Index - 1, tempField1);
	//m_listCtrl.SetItemText(tempItem, 1, _T(tempField2));
	//m_listCtrl.SetItemText(tempItem, 2, _T(tempField3));
	m_iSelect_NeedListCtrl_Index--;
	// 使得IndexInFieldList-1位置处项目高亮显示并获得焦点
	UINT flag = LVIS_SELECTED | LVIS_FOCUSED;
	m_list_needdealtask_info.SetItemState(m_iSelect_NeedListCtrl_Index, flag, flag);
}


void CPage1::OnBnClickedBtnMoveDown()
{
	// TODO: 在此添加控件通知处理程序代码
	m_list_needdealtask_info.SetFocus();
	if (m_iSelect_NeedListCtrl_Index == -1)
	{
		AfxMessageBox(L"请先选中");
		return;
	}
	if (m_iSelect_NeedListCtrl_Index == m_list_needdealtask_info.GetItemCount())
	{
		AfxMessageBox(L"已经位于最后一行!");
		return;
	}
	// 提取所选列表项各列类容
	CString tempField1;
	tempField1 = m_list_needdealtask_info.GetItemText(m_iSelect_NeedListCtrl_Index, 0);

	// 删除所选列表项
	m_list_needdealtask_info.DeleteItem(m_iSelect_NeedListCtrl_Index);
	// 在IndexInFieldList位置处插入上面所删列表项的各列类容
	int tempItem;
	tempItem = m_list_needdealtask_info.InsertItem(m_iSelect_NeedListCtrl_Index + 1, tempField1);
	//m_listCtrl.SetItemText(tempItem, 1, _T(tempField2));
	//m_listCtrl.SetItemText(tempItem, 2, _T(tempField3));
	m_iSelect_NeedListCtrl_Index++;
	// 使得IndexInFieldList-1位置处项目高亮显示并获得焦点
	UINT flag = LVIS_SELECTED | LVIS_FOCUSED;
	m_list_needdealtask_info.SetItemState(m_iSelect_NeedListCtrl_Index, flag, flag);
}


void CPage1::OnBnClickedBtnClearneeddeal()
{
	// TODO: 在此添加控件通知处理程序代码
	m_list_needdealtask_info.DeleteAllItems();
}


void CPage1::OnBnClickedBtnOnekeytoneeddealOfmaintask()
{
	// TODO: 在此添加控件通知处理程序代码
	m_list_needdealtask_info.DeleteAllItems();

	int iTaskNumber = m_GameTask_Page1.m_OneKeyMainTaskArray.GetSize();
	for (int i = 0; i < iTaskNumber; i++)
	{
		CString strTaskName = m_GameTask_Page1.m_OneKeyMainTaskArray.GetAt(i);
		m_list_needdealtask_info.InsertItem(i, strTaskName);

	}
	((CButton*)GetDlgItem(IDC_CHECK_QiHao))->SetCheck(1);
	((CButton*)GetDlgItem(IDC_CHECK_RiChang))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_Add_Friend))->SetCheck(0);

	g_IniFile.SetInt(L"Set", L"执行", 1);
}


void CPage1::OnBnClickedBtnOnekeytofb()
{
	// TODO: 在此添加控件通知处理程序代码
	m_list_needdealtask_info.DeleteAllItems();

	int iTaskNumber = m_GameTask_Page1.m_OneKeyDailyTaskArray.GetSize();
	for (int i = 0; i < iTaskNumber; i++)
	{
		CString strTaskName = m_GameTask_Page1.m_OneKeyDailyTaskArray.GetAt(i);
		m_list_needdealtask_info.InsertItem(i, strTaskName);

	}
	((CButton*)GetDlgItem(IDC_CHECK_QiHao))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_RiChang))->SetCheck(1);
	((CButton*)GetDlgItem(IDC_CHECK_Add_Friend))->SetCheck(0);

	g_IniFile.SetInt(L"Set", L"执行", 2);
}


void CPage1::OnBnClickedBtnAddFriend()
{
	// TODO: 在此添加控件通知处理程序代码
	m_list_needdealtask_info.DeleteAllItems();

	int iTaskNumber = m_GameTask_Page1.m_OneKeyAddFriend.GetSize();
	for (int i = 0; i < iTaskNumber; i++)
	{
		CString strTaskName = m_GameTask_Page1.m_OneKeyAddFriend.GetAt(i);
		m_list_needdealtask_info.InsertItem(i, strTaskName);
	}
	((CButton*)GetDlgItem(IDC_CHECK_QiHao))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_RiChang))->SetCheck(0);
	((CButton*)GetDlgItem(IDC_CHECK_Add_Friend))->SetCheck(1);

	g_IniFile.SetInt(L"Set", L"执行", 3);
}


void CPage1::OnNMClickListOriginaltaskInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	POSITION pos;
	pos = m_list_oritask_info.GetFirstSelectedItemPosition();
	if (pos != NULL)
	{
		// 得到项目索引
		m_iSelect_OriListCtrl_Index = m_list_oritask_info.GetNextSelectedItem(pos);
	}
	else {
		m_iSelect_OriListCtrl_Index = -1;
	}

	*pResult = 0;
}


void CPage1::OnNMDblclkListOriginaltaskInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;
	OnBnClickedBtnAddtoneeddeal();
}


void CPage1::OnNMClickListNeeddealtaskInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	POSITION pos;
	pos = m_list_needdealtask_info.GetFirstSelectedItemPosition();
	if (pos != NULL)
	{
		// 得到项目索引
		m_iSelect_NeedListCtrl_Index = m_list_needdealtask_info.GetNextSelectedItem(pos);
	}
	else
	{
		m_iSelect_NeedListCtrl_Index = -1;
	}

	*pResult = 0;

}


void CPage1::OnNMDblclkListNeeddealtaskInfo(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	OnBnClickedBtnDelfromneeddeal();
	*pResult = 0;
}


void CPage1::OnMemuImportaccount()
{
	// TODO: 在此添加命令处理程序代码
}


void CPage1::OnBnClickedBrowser()
{
	// TODO: 在此添加控件通知处理程序代码
	CFileDialog dlg(TRUE, NULL, NULL, 4 | 2, L"应用程序(*exe)|*.exe");

	if (dlg.DoModal() == IDOK) {
		//m_strGamePath = dlg.GetPathName();
		SetDlgItemText(IDC_EDIT_Simulator_Path, dlg.GetPathName());
	}
	//UpdateData(FALSE);
}


void CPage1::OnBnClickedBtnCloseAll()
{
	// TODO: 在此添加控件通知处理程序代码
	//m_GGameHwnd = (long)m_GlobalDM->FindWindow(L"MapleStoryClass", L"MapleStory");
	//int ret = m_GlobalDM->BindWindowEx(m_GGameHwnd, L"gdi", L"normal", L"normal", L"", 0);
	CString str;
	GetDlgItemTextW(IDC_EDIT_TEST, str);
	runScript(str);
	if (runScript(str)) {
		
		str.Format(L"%d", intX.lVal);
		AfxMessageBox(str);
	}

		//time_t timep;
		//time(&timep);
		//CString sTimeBmp;
		//sTimeBmp.Format(L"%d.bmp", timep);
		//m_GlobalDM->Capture(0, 0, 800, 600, sTimeBmp);
		//m_GlobalDM->delay(2000);
}
